package com.ccc.scala.base7_collection

import scala.collection.mutable

object Collection11_Set2 {

  def main(args: Array[String]): Unit = {
    // 可变 set
    val set1 = mutable.Set(1, 2, 3, 4)
    val set2 = mutable.Set(5, 6, 7, 8)

    // 增加数据
    set1.add(5)
    println(set1) // Set(1, 5, 2, 3, 4)

    // 增加数据
    set1.update(8, included = true)
    println(set1) // Set(1, 5, 2, 3, 4, 8)

    // 删除数据
    set1.update(8, included = false)
    println(set1) // Set(1, 5, 2, 3, 4)

    // 删除数据
    set1.remove(2)
    println(set1) // Set(1, 5, 3, 4)

    // 交集
    val set3 = set1 & set2
    println(set3) // Set(5)

    // 差集
    val set4 = set1 &~ set2
    println(set4) // Set(1, 3, 4)



  }

}
